<template>
  <div class="tobepaid">
    <div class="totalPaid">
      <div class="toepain-top">
        <van-nav-bar title="订单列表" left-arrow @click-left="clickReturn">
          <template #right>
            <div class="rigit-img" Dialog>
              <img class="auto-img" src="../assets/gantanhao.png" alt="" />
            </div>
          </template>
        </van-nav-bar>
      </div>
      <div class="nav-top">
        <!-- 事件绑定需要在最外层绑定 -->
        <van-tabs v-model="active"  @click="clickState">
          <van-tab
            :title="item.name"
            v-for="(item, index) in ToData"
            :key="index"
           
          >
            <div class="total-item">
              <div
                class="content"
                v-for="(item, index) in calculationBendiData"
                :key="index"
              >
                <div class="itme-top">
                  <div class="top-img">
                    <img
                      class="auto-img"
                      src="https://img2.baidu.com/it/u=46579649,821546474&fm=253&fmt=auto&app=138&f=PNG?w=500&h=500"
                      alt=""
                    />
                  </div>
                  <div class="top-content">
                    <div class="top-left-name">智能购商城自营</div>
                    <div class="top-right-name" v-if="item.type === 1">
                      待付款
                    </div>
                    <div class="top-right-name" v-if="item.type === 2">
                      待发货
                    </div>
                    <div class="top-right-name" v-if="item.type === 3">
                      待收货
                    </div>
                    <div class="top-right-name" v-if="item.type === 4">
                      待评价
                    </div>
                    <div class="top-right-name" v-if="item.type === 5">
                      退换货
                    </div>
                  </div>
                </div>

                <div
                  class="midden"
                  v-for="(value, vIndex) in item.daizhifu"
                  :key="vIndex"
                >
                  <div class="midden-img">
                    <img class="auto-img" :src="value.img" alt="" />
                  </div>
                  <div class="left">
                    <div class="midden-content">
                      <div class="midden-name .ovf-text">{{ value.name }}</div>
                      <div class="midden-class .ovf-text">
                        分类：{{ value.type }}
                      </div>
                      <div class="midden-footer">
                        <div class="qitian">{{ value.isqitian }}</div>
                        <div class="qitian">{{ value.isguanfang }}</div>
                      </div>
                    </div>
                  </div>
                  <div class="right">
                    <div class="price">
                      &yen;{{ value.currentPrice * value.iscount }}
                    </div>
                    <div class="right-count">x{{ value.iscount }}</div>
                  </div>
                </div>

                <div class="total-price">
                  <span class="spans">需付款</span>&yen;<span class="spans"
                    >343.</span
                  >00
                </div>

                <div class="footer-nav" v-if="item.type === 1">
                  <div class="dizi">修改地址</div>
                  <div class="dizi">找朋友付</div>
                  <div class="dizi" @click="PaymentPaid(item.currentTiem)">
                    付款
                  </div>
                </div>
                <div class="footer-nav" v-if="item.type === 2">
                  <div class="dizi">申请退款</div>
                  <div class="dizi">再次购买</div>
                  <div class="dizi" @click="clickFahuo(item.currentTiem)">催发货</div>
                </div>
                <div class="footer-nav" v-if="item.type === 3">
                  <div class="dizi">申请退款</div>
                  <div class="dizi">查看物流</div>
                  <div class="dizi" @click="clickshouhuo(item.currentTiem)">确认收货</div>
                </div>
                <div class="footer-nav" v-if="item.type === 4">
                  <div class="dizi" @click="clickPingjia(item.currentTiem)">评价</div>
                </div>
                <div class="footer-nav" v-if="item.type === 5">
                  <div class="dizi" @click="detelenData(item.currentTiem)">删除记录</div>
                  <div class="dizi">售后评价</div>
                  <div class="dizi">查看详情</div>
                </div>
              </div>
            </div>
          </van-tab>
        </van-tabs>
      </div>

      <div class="kong" v-show="(calculationBendiData.length == 0)">
        <van-empty description="您没有订单" v-if="state == 0">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
        <van-empty description="您没有待付款订单" v-if="(state == 1)">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
        <van-empty description="您没有待发货订单" v-if="(state == 2)">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
        <van-empty description="您没有待收货订单" v-if="(state == 3)">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
        <van-empty description="您没有待评价订单" v-if="(state == 4)">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
        <van-empty description="您没有已完成订单" v-if="(state == 5)">
          <van-button
            round
            type="danger"
            class="bottom-button"
            @click="JumpCategory"
            >去逛逛</van-button
          >
        </van-empty>
      </div>
    </div>

    <!-- 结算页面 -->
  </div>
</template>

<script>
export default {
  name: "ToBePaid",
  components: {
  },
  data() {
    return {
      active: 0,
      ToData: [
        {
          name: "全部",
          state: 0,
        },
        {
          name: "待付款",
          state: 1,
        },
        {
          name: "待发货",
          state: 2,
        },
        {
          name: "待收货",
          state: 3,
        },
        {
          name: "待评价",
          state: 4,
        },
        {
          name: "已完成",
          state: 5,
        },
      ],
      //本地储存数据
      bendiData: "",
      //结算页面状态
      state:0
    };
  },

  created() {
    this.totalToBePaidData();
    console.log("bendiData");
  },
  computed: {
    // 计算数据类型
   calculationBendiData(){
    if(this.bendiData == undefined){
      return
    }
      if(this.state == 0){
        return this.bendiData;
      }else if(this.state == 1){
        return this.bendiData.filter(item=>{
          return item.type == 1;
        })
      }else if(this.state == 2){
        return this.bendiData.filter(item=>{
          return item.type == 2;
        })
      }else if(this.state == 3){
        return this.bendiData.filter(item=>{
          return item.type == 3;
        })
      }else if(this.state == 4){
        return this.bendiData.filter(item=>{
          return item.type == 4;
        })
      }else if(this.state == 5){
        return this.bendiData.filter(item=>{
          return item.type == 5;
        })
      }
    }
  },
  methods: {
    //删除记录
    detelenData(id){
      this.bendiData.forEach((item) => {
        if (item.currentTiem === id) {
          this.$toast.loading({
            message: "加载中...",
            forbidClick: true,
            loadingType: "spinner",
          });
          setTimeout(() => {
            this.bendiData.splice(item,1)
            
          }, 1000);
        }
      });

      console.log("this.bendiData===>",this.bendiData);
      setTimeout(() => {
            
        //储存到本地
        window.localStorage.setItem("successData", JSON.stringify(this.bendiData));
          }, 1000);
    },
    //评价
    clickPingjia(id){

      this.bendiData.forEach((item) => {
        if (item.currentTiem === id) {
          this.$toast.loading({
            message: "加载中...",
            forbidClick: true,
            loadingType: "spinner",
          });
          console.log("item==>",item);
          setTimeout(() => {
            
            item.type = 5;
          }, 1000);

        }
      });
      setTimeout(() => {
            
        //储存到本地
        window.localStorage.setItem("successData", JSON.stringify(this.bendiData));
          }, 1000);
    },
    //确认收货
    clickshouhuo(id){

      this.bendiData.forEach((item) => {
        if (item.currentTiem === id) {
          this.$toast.loading({
            message: "加载中...",
            forbidClick: true,
            loadingType: "spinner",
          });
          console.log("item==>",item);
          setTimeout(() => {
            
            item.type = 4;
          }, 1000);

        }
      });
      setTimeout(() => {
            
        //储存到本地
        window.localStorage.setItem("successData", JSON.stringify(this.bendiData));
          }, 1000);
    },
    //催发货
    clickFahuo(id){
   //找到相同的订单号
   this.bendiData.forEach((item) => {
        if (item.currentTiem === id) {
          this.$toast.loading({
            message: "加载中...",
            forbidClick: true,
            loadingType: "spinner",
          });
          console.log("item==>",item);
          setTimeout(() => {
            
            item.type = 3;
          }, 1000);

        }
      });
      setTimeout(() => {
            
        //储存到本地
        window.localStorage.setItem("successData", JSON.stringify(this.bendiData));
          }, 1000);
    },
    //点击更改state的值
    clickState(value){
      //把点击的下标值赋值给state
      this.state = value
      // console.log("value=>",value);
    },
    //待付款付款
    PaymentPaid(id) {
      console.log("这个是订单号", id);
      let aaa = []
      //找到相同的订单号
      this.bendiData.forEach((item) => {
        if (item.currentTiem === id) {
          aaa.push(item)
          this.$toast.loading({
            message: "加载中...",
            forbidClick: true,
            loadingType: "spinner",
          
          });
          setTimeout(() => {
            this.$router.push({name:"JieSuan",params:{orderID:id,orderData:aaa}})
          }, 1000);

          // item.type = 2;
        }
      });
    },

    //拿到订单全部数据
    totalToBePaidData() {
      let totalSuccessData = JSON.parse(localStorage.getItem("successData"));

      this.bendiData = totalSuccessData;
    },
    //返回上一级
    clickReturn() {
      this.$router.push({name:"My"})
    },

    // 跳转分类页面
    JumpCategory() {
      this.$router.push({ name: "Category" });
    },
  },
};
</script>

<style lang="scss" scoped>
.total-item {
  margin-top: 10px;
}
.footer-nav {
  height: 40px;
  margin-top: 10px;
  display: flex;
  .dizi {
    height: 30px;
    width: 80px;
    border: 1px solid #000;
    margin-top: 5px;
    margin-left: auto;
    border-radius: 20px;
    line-height: 30px;
    text-align: center;
    font-weight: bold;
    font-size: 16px;
    &:nth-child(3n) {
      border: 1px solid #dd7238;
      color: #dd7238;
    }
  }
}
.total-price {
  margin-top: 10px;
  width: 100%;
  text-align: right;
  font-weight: bold;
  .spans {
    font-size: 18px;
  }
}
.midden {
  margin: 30px 0;
  display: flex;
  .right {
    width: 70px;
    .price {
      font-size: 16px;
      color: #000;
      font-weight: bold;
      text-align: right;
    }
    .right-count {
      text-align: right;
      font-size: 14px;
      margin-top: 5px;
    }
  }

  .left {
    .midden-content {
      width: 180px;
      height: 80px;
      margin-left: 10px;
      .midden-footer {
        display: flex;
        .qitian {
          padding: 0 2px;
          border: 1px solid #f46222;
          margin-right: 5px;
          border-radius: 3px;
          color: red;
        }
      }
      .midden-class {
        height: 30px;
        font-size: 16px;
        margin-top: 5px;
        color: #999;
      }
      .midden-name {
        font-size: 16px;
        font-weight: bold;
      }
    }
  }
  .midden-img {
    width: 80px;
    height: 80px;
    border: 1px solid rgb(214, 214, 214);
  }
}
.content {
  background-color: white;
  width: 96%;
  border-radius: 10px;
  margin: 5px auto;
  padding: 10px;
  box-sizing: border-box;
  .itme-top {
    height: 100%;
    display: flex;
    .top-content {
      display: flex;
      width: 305px;
      margin-left: 5px;
      line-height: 23px;
      font-size: 18px;
      .top-right-name {
        margin-left: auto;
        color: #dd7238;
      }
      .top-left-name {
        font-weight: bold;
      }
    }
    .top-img {
      width: 23px;
    }
  }
}
.bottom-button {
  width: 200px;
  height: 40px;
}
.rigit-img {
  width: 20px;
}
.tobepaid {
  position: fixed;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background-color: #eeeeee;
}
</style>